package com.ym.b2b.salesman.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.ym.b2b.salesman.dao.EmBSalesmanDAO;
import com.ym.b2b.salesman.sqlbean.EmBSalesman;
import com.zc.commons.base.Page;
import com.zc.commons.dao.ZcDao;

@Repository
public class EmBSalesmanDAOImpl<T> extends ZcDao<T> implements EmBSalesmanDAO {

    public Long searchPageEmBSalesmanNum(EmBSalesman embsalesman) throws DataAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embsalesman);
        return (Long) find("EM_B_SALESMAN.searchPageEmBSalesmanNum", map);
    }

    public Page searchPageEmBSalesman(EmBSalesman embsalesman, Page<EmBSalesman> page) throws DataAccessException {
        page.setTotalRow(searchPageEmBSalesmanNum(embsalesman));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embsalesman);
        map.put("startrow", page.getStartRow());
        map.put("pagesize", page.getPageSize());
        map.put("pageable", page.getPageable());
        page.setRows(list("EM_B_SALESMAN.searchPageEmBSalesman", map));
        return page;
    }

    public void insertEmBSalesman(EmBSalesman record) throws DataAccessException {
        insert("EM_B_SALESMAN.insertEmBSalesman", record);
    }

    public int updateEmBSalesman(EmBSalesman record) throws DataAccessException {
        int rows = update("EM_B_SALESMAN.updateEmBSalesman", record);
        return rows;
    }

    public int updateEmBSalesmanForType1(EmBSalesman record) throws DataAccessException {
        int rows = update("EM_B_SALESMAN.updateEmBSalesmanForType1", record);
        return rows;
    }

    public int updateEmBSalesmanForType2(EmBSalesman record) throws DataAccessException {
        int rows = update("EM_B_SALESMAN.updateEmBSalesmanForType2", record);
        return rows;
    }

    public EmBSalesman searchEmBSalesman(Long salesmanId) throws DataAccessException {
        EmBSalesman key = new EmBSalesman();
        key.setSalesmanId(salesmanId);
        EmBSalesman record = (EmBSalesman) find("EM_B_SALESMAN.selectEmBSalesman", key);
        return record;
    }

    public void deleteEmBSalesman(EmBSalesman emBSalesman) throws DataAccessException {
        delete("EM_B_SALESMAN.deleteEmBSalesman", emBSalesman);
    }

    @Override
    public EmBSalesman showEmBSalesmanDetail(EmBSalesman emBSalesman) throws DataAccessException {
        return (EmBSalesman) find("EM_B_SALESMAN.showEmBSalesmanDetail", emBSalesman);
    }

    @Override
    public void deleteMultipleEmBSalesmans(String salesmanIdList) {
        delete("EM_B_SALESMAN.deleteMultipleEmBSalesmans", salesmanIdList);
    }

}
